using namespace std;
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<iostream>
void reader(int rfd)
{
    char buffer[1024];
    while(true)
    {
        read(rfd,buffer,sizeof(buffer));
        cout<<"message:"<< buffer <<endl;
    }
}
void writer(int wfd)
{
    int count=0;
    while(true)
    {
        write(wfd,"c",1);
        count++;
        if(count==1024)
        {
            break;
        }
    }
    close(wfd);
    cout<<"writer close..."<<endl;
}
int main()
{
    int pipefd[2];
    pipe(pipefd);
    int wfd=pipefd[1];
    int rfd=pipefd[0];
    pid_t id= fork();
    if(id==0)
    {
        close(rfd);
        writer(wfd);
        exit(0);
    }
    close(wfd);
    reader(rfd);
    waitpid(id, nullptr, 0);
    return 0;
}